<?php

namespace Modules\Shop\Http\Resources;

use Modules\Shop\Models\Spu;
use Modules\Core\Models\User;
use Modules\Shop\Models\SpuExtend;
use Modules\Core\Http\Resources\BaseResource;

class SpuResource extends BaseResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'uid' => $this->uid,
            'category_id' => $this->category_id,
            'category_id_label' => $this->category->getParents()->implode('name', '/'),
            'thumb' => $this->thumb,
            'name' => $this->name,
            'status' => $this->status,
            'out_douyin_product_id' => $this->openShop->out_product_id ?? '',
            'count' => [
                'store' => $this->sku->sum('stock'),
                'sale' => 0
            ],
            'pay_type_label' => Spu::$pay_types[$this->pay_type] ?? '-',
            'created_at' => $this->created_at->format('Y-m-d H:i:s'),
//            'extend' => User::getOid() != $this->tenant_id ? $this->org->name : false
        ];
    }
}
